﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Secure.Common
{
    public abstract class SecuredResource : ISecuredResource
    {
        protected const string SEPARATOR = "/";

        private readonly string _resourcePrefix;
        private readonly List<ISecureUser> _allowedUsers = new List<ISecureUser>();

        protected SecuredResource(string resourcePrefix)
        {
            _resourcePrefix = resourcePrefix;
        }

        protected abstract string GetLocalPath();

        public string GetResourcePath()
        {
            return string.Concat(_resourcePrefix, SEPARATOR, GetLocalPath());
        }

        public bool AddAllowedUser(ISecureUser user)
        {
            _allowedUsers.Add(user);
            return true;
        }

        public bool IsAllowedAccess(ISecureUser user)
        {
            return _allowedUsers.Find((u) => u.UserName == user.UserName) != null;
        }
    }
}